// pages/dailysafecheckdes/dailysafecheckdes.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    problemDes: '',
    suggestion: '',
    src: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '日常安全检查',
    })
  },

  /**输入函数 */
  problemDes: function (event) {
    this.setData({
      problemDes: event.detail.value
    })
    console.log(event.detail.value)
  },

  /**输入函数 */
  suggestion: function (event) {
    this.setData({
      suggestion: event.detail.value
    })
    console.log(event.detail.value)
  },


  save: function (event) {
   
    console.log('data=', this.data.problemDes)
  },
  /**
   * 图片上传七牛云
   */
  uploadQiniu(tempFilePaths) {
    let token = this.data.token;
    var that = this;
    wx.uploadFile({
      url: 'http://img.izhihui2020.top',
      name: 'file',
      filePath: tempFilePaths[0],
      header: {
        "Content-Type": "multipart/form-data"
      },
      formData: {
        token: token,
      },
      success: function (res) {
        let data = JSON.parse(res.data)

        console.log('qiniu');
        console.log(res);
        // to do ...
      },
      fail: function (res) {
        console.log(res)
      }
    });
  },
  btn_upload_pic: function (e) {

  },

  btn_choice_pic: function (event) {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],

      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        that.setData({
          src: res.tempFilePaths
        })
        console.log('path=', res.tempFilePaths[0])
        //这里的key与token 找后台
        wx.uploadFile({
          url: "https://img.izhihui2020.top",
          filePath: res.tempFilePaths[0], //chooseImage上传的图片,是一个临时路径
          name: 'file',
          header: {
            "Content-Type": "multipart/form-data"
          },
          formData: {
            token: wx.getStorageSync('qiniuToken'),
            key: Math.random().toString(36).substr(2),
          },
          success(res) {
            // 这里返回key 与 hash
            console.log(res)
          },
          file: res => {
            console.log(res)
          }
        })

      }
    })
  },


})